library(ggiraph)library(glue)tooltip_css <-"background-color:#d8118c;color:white;padding:5px;border-radius:3px;"bg_color <-"#D7E0DA"font_color <-"#1f3225"df3 <- data%>%select(product_id, reordered, product_name)%>%group_by(product_id, product_name)%>% dplyr::summarize(proportion_reordered =mean(reordered), n=n())gg_scatter <-ggplot(data = df3,mapping =aes(x=n, y=proportion_reordered,# here we add iteractive aestheticstooltip =paste0(toupper(product_name), ":", n))) +geom_jitter_interactive(size =3, hover_nearest =TRUE)+geom_smooth(aes(tooltip="smoothed line", data_id="smooth"), se=FALSE)+labs(y ="Proportion of reorders",title="Association between number of orders and probability of reordering",caption ="Products with a high number of orders are naturally more likely to be reordered.\nHowever, there seems to be a ceiling effect.")+theme_minimal()+theme(text=element_text(family ="chivo", color="#1f3225"), panel.grid.minor =element_blank(),panel.grid.major =element_line(color="#1f3225", size=0.1),axis.title=element_text(face="bold", size=10),axis.text =element_text(color="#1f3225"),axis.title.y=element_text(margin=margin(r=10)),plot.title =element_text(size =13, face ="bold", hjust =0.5, vjust =0.5),plot.margin =margin(20,20,20,20))## Customizing girafe animationsgirafe(ggobj = gg_scatter,bg = bg_color,options =list(opts_tooltip(css = tooltip_css, opacity =1),opts_sizing(width = .7),opts_zoom(max =1),opts_hover(css =girafe_css(css =glue("fill:{font_color};"),text =glue("stroke:none;fill:{font_color};fill-opacity:1;")))))